package ru.dc.object.commands;

/**
 * <h2>Syntax</h2>
 * <pre>$Hello &lt;nick>|</pre>
 *
 * <p><b>Description</b> Hello is part of the Client-Hub Handshake and is sent to the client to indicate
 * which nickname the hub will identify the client with.</p>
 *
 * <ul><li>&lt;nick> is the client's nickname. The Hello command is also used to announce newly connected clients.</li></ul>
 * <a href="http://www.teamfair.info/wiki/index.php?title=$Hello">http://www.teamfair.info/wiki/index.php?title=$Hello</a>
 */
public class Hello extends Command {

    private String nick;

    @Override
    public String generateCommand() {
        return getActualCommandName()+" "+getNick();
    }

    @Override
    public String getActualCommandName() {
        return "$Hello";
    }

    @Override
    public void parseCommand() {
        if (getCommand().length()>7) {
            setNick(getCommand().substring(7));
        }
        else {
            setNick(null);
        }
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    @Override
    public String toString() {
        return "Hello{" +
                "nick='" + nick + '\'' +
                '}';
    }
}
